package de.wittekind.bundesjugendspiele.dummy;

import java.io.IOException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import de.wittekind.bundesjugendspiele.server.interfaces.Discipline;
import de.wittekind.bundesjugendspiele.server.interfaces.Riege;
import de.wittekind.bundesjugendspiele.server.interfaces.RiegenLoader;
import de.wittekind.bundesjugendspiele.server.interfaces.Schueler;
import de.wittekind.bundesjugendspiele.server.interfaces.Try;
import de.wittekind.bundesjugendspiele.server.interfaces.Unit;

public class DummyRiegenLoader implements RiegenLoader {

	ArrayList<Riege> riegenList;

	public DummyRiegenLoader() throws IOException {
		int id = 1;
		riegenList = new ArrayList<Riege>();
		String[] firstName = { "David", "John D.", "Vinton", "Brad", "Brian",
				"Dave", "Roberto", "Donald E.", "Sophie" };
		String[] lastName = { "Bradley", "Carmack", "Serf", "Cox", "Fox",
				"Hyatt", "Ierusalimschy", "Knuth", "Wilson" };

		for (int i = 0; i < 20; i++) {
			ArrayList<Schueler> r = new ArrayList<Schueler>();
			for (int x = 0; x < lastName.length; x++) {
				Schueler d = new DummySchueler(id);
				try {
					d.setFirstName(firstName[x]);
					d.setLastName(lastName[x]);
					d.setBirthday(new GregorianCalendar(2000, 11, 4));

					// Sample tries

					Try[] tries = new Try[6];
					tries[0] = new DummyTry();
					tries[0].setDiscipline(Discipline.SPRINT100);
					tries[0].setUnit(Unit.s);
					tries[0].setValue(0);
					tries[1] = new DummyTry();
					tries[1].setDiscipline(Discipline.WURF200);
					tries[1].setUnit(Unit.m);
					tries[1].setValue(0);
					tries[2] = new DummyTry();
					tries[2].setDiscipline(Discipline.WURF200);
					tries[2].setUnit(Unit.m);
					tries[2].setValue(0);
					tries[3] = new DummyTry();
					tries[3].setDiscipline(Discipline.WURF200);
					tries[3].setUnit(Unit.m);
					tries[3].setValue(0);
					tries[4] = new DummyTry();
					tries[4].setDiscipline(Discipline.WEITSPRUNG);
					tries[4].setUnit(Unit.m);
					tries[4].setValue(0);
					tries[5] = new DummyTry();
					tries[5].setDiscipline(Discipline.AUSDAUER1000);
					tries[5].setUnit(Unit.min);
					tries[5].setValue(0);

					d.setTries(tries);
				} catch (IOException e) {

				}

				r.add(d);
				id++;
			}
			riegenList.add(new DummyRiege(r));
		}
	}

	@Override
	public Riege getRiege(int id) {
		return riegenList.get(id - 1);
	}

	@Override
	public int getRiegenAmount() {
		return riegenList.size();
	}

	@Override
	public int newRiege() throws IOException {
		riegenList.add(new DummyRiege(new ArrayList<Schueler>()));
		return riegenList.size();
	}

	@Override
	public void removeRiege(int i) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public Schueler[] getAllSchueler(int Jahrgang) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Map<Schueler, Try> getLatestResults(int count,
			Discipline discipline, int year) throws IOException {
		// TODO Auto-generated method stub
		Map<Schueler, Try> map = new HashMap<Schueler, Try>();
		int[] schuelerIds = this.getRiege(1).getSchuelerIDs();
		for (int i = 0; i < count; i++) {
			int schuelerId = schuelerIds[i];
			Schueler s = this.getRiege(1).getSchueler(schuelerId);
			Try tr = new DummyTry();
			tr.setDiscipline(discipline);
			tr.setUnit(Unit.m);
			tr.setValue(new Random().nextDouble());
			map.put(s, tr);
		}

		return map;
	}

	@Override
	public Map<Schueler, Try> getBestResults(int count, Discipline discipline)
			throws IOException {
		return getLatestResults(count, discipline, 0);
	}

	@Override
	public Map<Schueler, Try> getBestResults(int count, Discipline discipline,
			int year) throws IOException {
		return getLatestResults(count, discipline, 0);
	}

	@Override
	public Map<Schueler, Try> getLatestResults(int count, Discipline discipline)
			throws IOException {
		return getLatestResults(count, discipline, 0);
	}

	@Override
	public int getMinJahrgang() throws IOException {
		// TODO implement
		return 0;
	}

	@Override
	public int getMaxJahrgang() throws IOException {
		// TODO implement
		return 0;
	}

	@Override
	public ArrayList<Integer> getSiegerurkunden() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Integer> getEhrenurkunden() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}



}
